/**
 * ...
 * @author Krzysztof Rozalski
 */

package hapi.util.profiler;
import haxe.PosInfos;

class CodeMemoryUsage {
	
	var marks:Array<MemoryUsageMark>;

	public function new() {
		marks = new Array<MemoryUsageMark>();
	}
	
	public function mark(label:String, ?info:PosInfos) {
		#if flash9
		var mem = flash.system.System.totalMemory;
		#else
		var mem = 0.0;
		#end
		marks.push( new MemoryUsageMark(label, mem, info) );
	}
	
	public function summary():String {
		var buf = new StringBuf();
		var prev = 0.0;
		for ( i in 0...marks.length ) {
			var m:MemoryUsageMark = marks[i];
			buf.add(m.toSummaryString(prev));
			prev = m.bytes;
		}
		return buf.toString();
	}
}